﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using PaperPluginUtilities;

namespace t_PaperPluginUtilities
{
    /// <summary>
    /// Test the HTML cleaner and make sure that it will make all text "good".
    /// </summary>
    [TestClass]
    public class t_CleanHTML
    {
        [TestMethod]
        public void TestNormalText()
        {
            Assert.AreEqual("hi", "hi".CleanHTMLText(), "Simple hi should cause no trouble!");
            Assert.AreEqual("hi aren't you there!", "hi aren't you there!", "Simple quote should not go away");
        }

        [TestMethod]
        public void TestSpecialCharacterLessThan()
        {
            Assert.AreEqual("This is a test < you", "This is a test &lt; you".CleanHTMLText(), "Didn't get the less than sign right");
        }

        [TestMethod]
        public void TestHexValueB()
        {
            Assert.AreEqual("This test", "This &#xB; test".CleanHTMLText(), "Hex character B not dealt with correctly");
            Assert.AreEqual("This test", "This &#xb; test".CleanHTMLText(), "Hex character B not dealt with correctly");
        }

        [TestMethod]
        public void TestRemoveComments()
        {
            Assert.AreEqual("This is a test", "This is <!-- fork it over -->a test".CleanHTMLText(), "Comment didn't get dropped");

            string longComment = "<!-- a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_p18_public/\">--><!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_p17_public/\">--><!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_Combined_LJ_DIL_Fit/\">--><!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2007/mass/ljets_tmt/\">--><!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2006/mass/ljets_tmt/\">-->with in-situ W->jj JES calibration";
            Assert.AreEqual("with in-situ W->jj JES calibration", longComment.CleanHTMLText(), "Long Cleaning didn't come out right!");

            string embeddedComment = "<!-- hi there-->test<!-- second one-->";
            Assert.AreEqual("test", embeddedComment.CleanHTMLText(), "The central phrase got eaten!");

            longComment = "<!-- a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_p18_public/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_p17_public/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_Combined_LJ_DIL_Fit/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2007/mass/ljets_tmt/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2006/mass/ljets_tmt/\">-->\nMtoprecowith in-situ W->jj JES calibration";
            Assert.AreEqual("Mtoprecowith in-situ W->jj JES calibration", longComment.CleanHTMLText(), "Can't deal with this special messy string");

            longComment = "\n<!-- a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_p18_public/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_p17_public/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2008/mass/TMT_Combined_LJ_DIL_Fit/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2007/mass/ljets_tmt/\">-->\n<!--<a href=\"http://www-cdf.fnal.gov/physics/new/top/2006/mass/ljets_tmt/\">-->\nMtoprecowith in-situ W->jj JES calibration";
            Assert.AreEqual("Mtoprecowith in-situ W->jj JES calibration", longComment.CleanHTMLText(), "Can't deal with this special messy string");
        }

        [TestMethod]
        public void TestSpecialCharacters()
        {
            Assert.AreEqual("Candidate for Z->mumu decay, collected on 10 May 2010.", "Candidate for Z&#8594;&#956;&#956; decay, collected on 10 May 2010.".CleanHTMLText(), "");
            Assert.AreEqual("pT(mu+) = 45 GeV", "pT(&#956;+) = 45 GeV".CleanHTMLText(), "Sub/super, etc. not correct");
            Assert.AreEqual("eta(mu+) = 2.2", "&#951;(&#956;+) = 2.2".CleanHTMLText(), "Eta bad");
        }
    }
}
